#include <iostream>
#include <stdio.h>

class Base
{
	public:
		void function_1()
		{
			printf("function_1...\n");
		}

		virtual void function_2()
		{
			printf("function_2...\n");
		}
};

int main(int argc, char ** argv)
{
	Base base;
	Base *pb;

	pb = &base;

	printf("size %d\n", sizeof(class Base));	// 4

	pb->function_1();
	pb->function_2();
}

/*
	function_1...
	function_2...
 */

#if 0

1.当virtual通过对象去调用时与普通函数没有区别，是直接（E8)调用。
2.当virtual通过指针去调用时生成的调用是个间接（FF）调用。

int main(int argc, char ** argv)
{
 8048640:	55                   	push   %ebp
 8048641:	89 e5                	mov    %esp,%ebp
 8048643:	83 e4 f0             	and    $0xfffffff0,%esp
 8048646:	83 ec 20             	sub    $0x20,%esp
	Base base;
 8048649:	8d 44 24 18          	lea    0x18(%esp),%eax
 804864d:	89 04 24             	mov    %eax,(%esp)
 8048650:	e8 af 00 00 00       	call   8048704 <_ZN4BaseC1Ev>
	Base *pb;

	pb = &base;
 8048655:	8d 44 24 18          	lea    0x18(%esp),%eax
 8048659:	89 44 24 1c          	mov    %eax,0x1c(%esp)

	pb->function_1();
 804865d:	8b 44 24 1c          	mov    0x1c(%esp),%eax		# this 指针，此乃函数放类或结构体里面和外面唯一的区别。放里面有多传this指针。
 8048661:	89 04 24             	mov    %eax,(%esp)
 8048664:	e8 73 00 00 00       	call   80486dc <_ZN4Base10function_1Ev>		# E8 call 是直接调用
	pb->function_2();
 8048669:	8b 44 24 1c          	mov    0x1c(%esp),%eax	# *this
 804866d:	8b 00                	mov    (%eax),%eax
 804866f:	8b 00                	mov    (%eax),%eax
 8048671:	8b 54 24 1c          	mov    0x1c(%esp),%edx	# *this
 8048675:	89 14 24             	mov    %edx,(%esp)
 8048678:	ff d0                	call   *%eax		# FF call 是间接调用
}
 804867a:	b8 00 00 00 00       	mov    $0x0,%eax
 804867f:	c9                   	leave  
 8048680:	c3                   	ret


#endif
